package com.kang.c0c.util;

/**
 * A class that encodes and decodes source code positions. Source code
 *  positions are internally represented as integers that contain
 *  both column and line number information.
 * 
 * 类Position定义了以一个整数来存储词法分析时记号所在行列信息的数据结构
 * 
 * 借鉴自GJC源代码
 *  
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Position {
	/**
     * Source file positions are integers in the format:
     *  line-number << LINESHIFT + column-number
     *  NOPOS represents an undefined position.
     */
	
	public static final int LINESHIFT = 10;
	public static final int COLUMNMASK = (1 << LINESHIFT) - 1;
	public static final int NOPOS = 0;
	public static final int FIRSTPOS = (1 << LINESHIFT) + 1;
	public static final int MAXPOS = Integer.MAX_VALUE;
	
	public static int make(int line,int col){
		return line<<LINESHIFT | col;
	}
	
	public static int getLine(int pos){
		return pos>>>LINESHIFT;
	}
	
	public static int getColumn(int pos){
		return pos&COLUMNMASK;
	}
	
	
}
